{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# source: https://en.wikipedia.org/wiki/Gradient_descent\n",
    "# From calculation, it is expected that the local minimum occurs at x=9/4\n",
    "\n",
    "current_x = 0.5 # The algorithm starts at x=6\n",
    "learning_rate = 0.01 # step size multiplier\n",
    "epoch = 60 # the number of times to train the function\n",
    "\n",
    "def result_of_the_equation(x): \n",
    "    return 5 * x**4 - 6 * x**2\n",
    "\n",
    "for i in range(epoch):\n",
    "    previous_x = current_x\n",
    "    current_x += -learning_rate * result_of_the_equation(previous_x)\n",
    "    print(previous_x)\n",
    "\n",
    "print(\"The local minimum occurs at %f\" % current_x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
